package com.atguigu.gulimall.product.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.atguigu.common.valid.AddGroup;
import com.atguigu.common.valid.UpdateGroup;
import com.atguigu.common.valid.UpdateStatusGroup;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.atguigu.gulimall.product.entity.PmsBrandEntity;
import com.atguigu.gulimall.product.service.PmsBrandService;
import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;


/**
 * 品牌
 *
 * @author yaotingkun
 * @email 1371364676@qq.com
 * @date 2021-10-13 14:21:50
 */
@RestController
@RequestMapping("product/brand")
public class PmsBrandController {
    @Autowired
    private PmsBrandService pmsBrandService;

    @ApiOperation(value = "商品系统--品牌管理--分页查询")
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = pmsBrandService.queryPage(params);
        return R.ok().put("page", page);
    }

    @ApiOperation(value = "商品系统--品牌管理--新增按钮")
    @RequestMapping("/save")
    public R save(@Validated(AddGroup.class) @RequestBody PmsBrandEntity pmsBrand){
        pmsBrandService.save(pmsBrand);
        return R.ok();
    }

    @ApiOperation(value = "商品系统--品牌管理--显示状态按钮修改")
    @RequestMapping("/update/status")
    public R updateStatus(@Validated(UpdateStatusGroup.class) @RequestBody PmsBrandEntity brand){
        pmsBrandService.updateDetail(brand);
        return R.ok();
    }

    @ApiOperation(value = "商品系统--品牌管理--操作修改")
    @RequestMapping("/update")
    public R update(@Validated(UpdateGroup.class) @RequestBody PmsBrandEntity pmsBrand){
        pmsBrandService.updateById(pmsBrand);
        return R.ok();
    }

    @ApiOperation(value = "商品系统--品牌管理--操作删除")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
        pmsBrandService.removeByIds(Arrays.asList(brandIds));
        return R.ok();
    }

    @ApiOperation(value = "信息")
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		PmsBrandEntity pmsBrand = pmsBrandService.getById(brandId);
        return R.ok().put("brand", pmsBrand);
    }

    /**
     * 信息
     */
    @RequestMapping("/infos")
    public R info(@RequestParam("brandIds") List<Long> brandIds){
        List<PmsBrandEntity> brand = pmsBrandService.getBrandsById(brandIds);
        return R.ok().put("brand", brand);
    }









}
